#!/bin/sh

# self_exe='self_develop_exe.json'
self_script_1='./selfdevelop/script_AccessControl.json'
self_script_2='./selfdevelop/script_AntiMalware.json'
self_script_3='./selfdevelop/script_Authentication.json'
self_script_4='./selfdevelop/script_IntrusionGuard.json'
self_script_5='./selfdevelop/script_SecurityAudit.json'

usage() {
    echo "USAGE: ./Conf.sh [OPTIONS]"
    echo "OPTIONS:"
    echo " scan       set command value 1 for all plugins in self_develop_script."
    echo " defend     set command value 2 for all plugins in self_develop_script."
    echo " rollback   set command value 3 for all plugins in self_develop_script."
}

scan() {
    sed -i 's/".*command.*/"command": 1/' ${self_script_1}
    sed -i 's/".*command.*/"command": 1/' ${self_script_2}
    sed -i 's/".*command.*/"command": 1/' ${self_script_3}
    sed -i 's/".*command.*/"command": 1/' ${self_script_4}
    sed -i 's/".*command.*/"command": 1/' ${self_script_5}
    # sed -i "s/-c\\s* ./-c 1/" ${self_exe}
}

defend() {
    sed -i 's/".*command.*/"command": 2/' ${self_script_1}
    sed -i 's/".*command.*/"command": 2/' ${self_script_2}
    sed -i 's/".*command.*/"command": 2/' ${self_script_3}
    sed -i 's/".*command.*/"command": 2/' ${self_script_4}
    sed -i 's/".*command.*/"command": 2/' ${self_script_5}
    # sed -i "s/-c\\s* ./-c 2/" ${self_exe}
}

rollback() {
    sed -i 's/".*command.*/"command": 3/' ${self_script_1}
    sed -i 's/".*command.*/"command": 3/' ${self_script_2}
    sed -i 's/".*command.*/"command": 3/' ${self_script_3}
    sed -i 's/".*command.*/"command": 3/' ${self_script_4}
    sed -i 's/".*command.*/"command": 3/' ${self_script_5}
    # sed -i "s/-c\\s* ./-c 3/" ${self_exe}
}

case "$1" in
    "scan")
        scan;;
    "defend")
        defend;;
    "rollback")
        rollback;;
    *)
    usage
    ;;

esac
exit 0
